﻿using System;
using Missbot.Common;
using Missbot.Core.Base;
using Missbot.Service;
using MongoDB.Bson.Serialization.Attributes;

namespace Missbot.Core.Common
{
    /// <summary>
    /// AI效能分析器
    /// </summary>
    public class AIAnalyzer
    {
        /// <summary>
        /// 系统启动时间
        /// </summary>
        public static DateTime Sys_StartTime { get; set; }
    }

    /// <summary>
    /// 输出日志
    /// </summary>
    public class OutboxRec : DbBaseEntity
    {
        /// <summary>
        /// 目标用户ID
        /// </summary>
        public string UserID { get; set; }
        
        /// <summary>
        /// 目标用户名
        /// </summary>
        public string UserName { get; set; }
        
        /// <summary>
        /// 目标群组ID
        /// </summary>
        public string GroupID { get; set; }
        
        /// <summary>
        /// 实例名
        /// </summary>
        public string Host { get; set; }
        
        /// <summary>
        /// 输出内容
        /// </summary>
        public string Text { get; set; }
        
        /// <summary>
        /// 输入频道名
        /// </summary>
        public string Channel { get; set; }
        
        /// <summary>
        /// 创建时间
        /// </summary>
        [BsonDateTimeOptions(Kind = DateTimeKind.Local)]
        public DateTime CreateTime { get; set; } = DateTime.Now;
    }

    public static class OutboxRecDA
    {
        public static void Record(OutboxDTO dto, string ChannelName)
        {
            var rec = new OutboxRec
                      {
                          UserID   = dto.User?.ID,
                          UserName = dto.User?.UserName,
                          GroupID  = dto.Group?.ID,
                          Host     = dto.User?.Host ?? Configger<AIConfigBase>.AIConfig.Instance.LocalHost,
                          Text     = dto.Text,
                          Channel  = ChannelName
                      };
            MongoService<OutboxRec>.Insert(rec);
        }
    }
}